<h1>标记品牌</h1>
<table class="table table-hover">
  <thead>
  <tr>
    <th>
      #
    </th>
    <th>
      品牌
    </th>
    <th>
      操作
    </th>
  </tr>
  </thead>
  <tbody>
  </tbody>
</table>
<script>
  $(function () {
    $.get('/product/tags/all', function (callback) {
      console.log(callback);
      for(var i=0; i<callback.length; i++) {
          var id = i+1;
          $('tbody').append('<tr><th>'+id+'</th><td>'+callback[i].brand+'</td><td><button class="btn btn-success" data-name="'+callback[i].brand+'">设为标记品牌</button></td></tr>')
      }
    });
    $(document).on('click', 'button', function () {
      var thisButton = this;
      console.log($(this).text());
      var brand = $(this).data('name');
      $.get('/admin/product/featured/'+brand, function (callback) {
        console.log(callback);
        if (callback == 'ok') {
            $(thisButton).text('取消标记');
            $(thisButton).removeClass('btn-success').addClass('btn-primary btn-cancel');
        }
      })
    });
    $(document).on('click', '.btn-cancel', function () {
      console.log(this);
      var thisCancel = this;
      var brand = $(thisCancel).data('name');
      $.get('/admin/product/cancelFeatured/'+brand, function (call) {
        if (call == 'ok') {
            $(thisCancel).text('设为标记品牌');
            $(thisCancel).removeClass('btn-primary btn-cancel').addClass('btn-success');
        }
      })
    })
  })
</script>

